﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BBMS.DLL.DataContract
{
    public class ChungTuChietKhau : ChungTuBase
    {
        public ChungTuChietKhau()
        {
            this.LoaiCT = "CTCK";
            this.IsChi = false;
        }

        public ChungTuChietKhau(long id, /*string maCT, string soCT,*/
             DateTime ngayCT, DateTime ngayHT, DateTime ngayTTDuKien,
             DateTime ngayTT, TrangThaiThanhToan trangThaiTT,
             string maSoHS, string maNCC, string maQuay, long giaTriCT, long giaTriDaTT, 
            string ghiChu,
             int nvID)
            : base(id, "CTCK", /*maCT, soCT, */"","",ngayCT, ngayHT, ngayTTDuKien, ngayTT, trangThaiTT, maSoHS,
                maNCC,maQuay, "", giaTriCT, 0, giaTriCT, 0, 0, giaTriCT,
                giaTriDaTT, "", false, false, ghiChu, nvID)
        {
            this.LoaiCT = "CTCK";
            this.IsChi = false;

        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);

            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("MaCT", typeof(String));
            dt.Columns.Add("SoCT", typeof(String));
            dt.Columns.Add("LoaiCT", typeof(String));
            dt.Columns.Add("NgayCT", typeof(DateTime));
            dt.Columns.Add("NgayHT", typeof(DateTime));
            dt.Columns.Add("NgayTTDuKien", typeof(DateTime));
            dt.Columns.Add("NgayTT", typeof(DateTime));
            dt.Columns.Add("TrangThaiTT", typeof(int));
            dt.Columns.Add("MaHoSo", typeof(String));
            dt.Columns.Add("MaNCC", typeof(String));
            dt.Columns.Add("MaQuay", typeof(String));

            dt.Columns.Add("GiaTriHangHoa", typeof(long));
            dt.Columns.Add("GiaTriChuaThue", typeof(long));
            dt.Columns.Add("GiaTriCT", typeof(long));
            dt.Columns.Add("GiaTriDaTT", typeof(long));

            dt.Columns.Add("GhiChu", typeof(String));
            dt.Columns.Add("IsChi", typeof(bool));

            dt.Columns.Add("NVID", typeof(int));

            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["ID"] = this.ID;
            row["MaCT"] = this.MaCT;
            row["SoCT"] = this.SoCT;
            row["LoaiCT"] = this.LoaiCT;
            row["NgayCT"] = this.NgayCT;
            row["NgayHT"] = this.NgayHT;
            row["NgayTTDuKien"] = this.NgayTTDuKien;
            row["NgayTT"] = this.NgayTT;
            row["TrangThaiTT"] = (int)this.TrangThaiTT;
            row["MaHoSo"] = this.MaHoSo;
            row["MaNCC"] = this.MaNCC;
            row["MaQuay"] = this.MaQuay;
            row["GiaTriHangHoa"] = this.GiaTriHangHoa;
            row["GiaTriChuaThue"] = this.GiaTriChuaThue;
            row["GiaTriCT"] = this.GiaTriCT;
            row["GiaTriDaTT"] = this.GiaTriDaTT;

            row["GhiChu"] = this.GhiChu;
            row["IsChi"] = this.IsChi;

            row["NVID"] = this.NVID;

            return row;
        }
        public override string[]  KeyFields
        {
	        get 
	        { 
		         return null;
	        }
        }
        public override void UpdateInsertedID(MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            cmd.CommandText = "SELECT LAST_INSERT_ID()";
            this.ID = CommonTools.Helper.StringToLong(cmd.ExecuteScalar().ToString());
        }
        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return false;
        }
        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            ChungTuChietKhau obj = null;
            try
            {
                obj = new ChungTuChietKhau(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    //row["MaCT"].ToString(),
                    //row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }

        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader row)
        {
            ChungTuChietKhau obj = null;
            try
            {
                obj = new ChungTuChietKhau(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    //row["MaCT"].ToString(),
                    //row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
    }

    /*
    public class ChungTuChietKhau : BBMS.DLL.Base.ObjectBase
    {
        public long ID;
        public string MaCT;
        public string SoCT;
        public string LoaiCT = "CTCK";
        public DateTime NgayCT;
        public DateTime NgayHT; // ngay hoach toan
        public DateTime NgayTT;
        public DateTime NgayTTDuKien;
        public string MaNCC;
        public string MaCTyThuHo;
        public string MaHoSo;
        public long GiaTri;
        public string GhiChu;
        public bool IsChi = false;
        public TrangThaiThanhToan TrangThaiTT = TrangThaiThanhToan.ChuaTT;
        public int NVID = 0;

        public ChungTuChietKhau()
        {
        }

        public ChungTuChietKhau(long id, string maCT, string soCT,
            DateTime ngayCT, DateTime ngayHT, DateTime ngayTT, string maHoSo,
            string maNCC, long giatri, string ghiChu, TrangThaiThanhToan trangThaiTT, int nvid)
        {
            this.ID = id;
            this.MaCT = maCT;
            this.SoCT = soCT;
            this.NgayCT = ngayCT;
            this.NgayHT = ngayHT;
            this.NgayTT = ngayHT;
            this.NgayTTDuKien = ngayHT;
            this.MaHoSo = maHoSo;
            this.MaNCC = maNCC;
            this.GiaTri = giatri;
            this.GhiChu = ghiChu;
            this.TrangThaiTT = trangThaiTT;
            this.NVID = nvid;
        }

        public override object Key
        {
            get
            {
                return this.ID;
            }
        }
        public override string Name
        {
            get
            {
                return this.MaCT + "-" + this.SoCT;
            }
        }
        public override string TableName
        {
            get
            {
                return "bill";
            }
        }

        public override string[] KeyFields
        {
            get
            {
                return new string[] { "MaCT", "SoCT" };
            }
        }

        public override string[] IDFields
        {
            get
            {
                return new string[] { "ID" };
            }
        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);
            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("MaCT", typeof(String));
            dt.Columns.Add("SoCT", typeof(String));
            dt.Columns.Add("LoaiCT", typeof(String));
            dt.Columns.Add("NgayCT", typeof(DateTime));
            dt.Columns.Add("NgayHT", typeof(DateTime));
            dt.Columns.Add("NgayTTDuKien", typeof(DateTime));
            dt.Columns.Add("NgayTT", typeof(DateTime));
            dt.Columns.Add("MaHoSo", typeof(String));
            dt.Columns.Add("MaNCC", typeof(String));
            dt.Columns.Add("GiaTri", typeof(long));
            dt.Columns.Add("GhiChu", typeof(String));
            dt.Columns.Add("TrangThaiTT", typeof(int));
            dt.Columns.Add("IsChi", typeof(bool));
            dt.Columns.Add("NVID", typeof(int));

            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["ID"] = this.ID;
            row["MaCT"] = this.MaCT;
            row["SoCT"] = this.SoCT;
            row["LoaiCT"] = this.LoaiCT;
            row["IsChi"] = this.IsChi;
            row["NgayCT"] = this.NgayCT;
            row["NgayHT"] = this.NgayHT;
            row["NgayTTDuKien"] = this.NgayTTDuKien;
            row["NgayTT"] = this.NgayTT;
            row["MaHoSo"] = this.MaHoSo;
            row["MaNCC"] = this.MaNCC;
            row["GiaTri"] = this.GiaTri;
            row["GhiChu"] = this.GhiChu;
            row["TrangThaiTT"] = (int)this.TrangThaiTT;
            row["NVID"] = this.NVID;
            return row;
        }

        public override void UpdateInsertedID(MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            cmd.CommandText = "SELECT LAST_INSERT_ID()";
            this.ID = CommonTools.Helper.StringToLong(cmd.ExecuteScalar().ToString());
        }
        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return true;
        }
        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            ChungTuChietKhau obj = null;
            try
            {
                obj = new ChungTuChietKhau(CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTT"],
                    //(DateTime)row["NgayTTDuKien"],
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTri"].ToString()),
                    row["GhiChu"].ToString(),
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
        public override string ExWhereClause
        {
            get
            {
                return " LoaiCT = 'CTCK' ";
            }
        }
        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader rd)
        {
            ChungTuChietKhau obj = null;
            try
            {
                obj = new ChungTuChietKhau(CommonTools.Helper.StringToLong(rd["ID"].ToString()),
                    rd["MaCT"].ToString(),
                    rd["SoCT"].ToString(),
                    (DateTime)rd["NgayCT"],
                    (DateTime)rd["NgayHT"],
                    (DateTime)rd["NgayTT"],
                    //(DateTime)rd["NgayTTDuKien"],
                    rd["MaHoSo"].ToString(),
                    rd["MaNCC"].ToString(),
                    CommonTools.Helper.StringToLong(rd["GiaTri"].ToString()),
                    rd["GhiChu"].ToString(),
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(rd["TrangThaiTT"].ToString())),
                    CommonTools.Helper.StringToInt(rd["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
    }*/
}
